-#
  Copyright 2008 Garth Williams

  This file is part of CommandPost.

  CommandPost is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  CommandPost is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with CommandPost.  If not, see <http://www.gnu.org/licenses/>.


%table
  %tr
    %td{:valign => 'top'}
      = error_messages_for :stage
      .box-title Edit Stage
      .box
        .float-right
          = link_to_remote '<img src="/images/delete.png"/>', :url => report_type_stage_path(@report_type, @stage), :confirm => "Delete #{h(@stage.name)}?\n\nPaths that link to this stage will also be removed!", :update => :report_type, :method => :delete
        - remote_form_for([@report_type, @stage], :update => { :success => 'report_type', :failure => 'stage' }) do |f|
          .input
            Name
            %br
            = f.text_field :name, :class => 'input_text'
          .input
            Data Capture
            %br
            ~ f.text_area :data_capture, :class => 'input_textarea', :title => "Example:\n\nName = text\nObservation = textarea\nEstimate = number\nColour = [red,green,blue]\nWhen = date\nMandatory* = text"
          .input
            = f.check_box :final_stage
            = f.label :final_stage, 'Final Stage'
            %br
            = f.check_box :allow_source_binding
            = f.label :allow_source_binding, 'Allow Source Binding'
            %br
            = f.check_box :allow_commits
            = f.label :allow_commits, 'Allow Commits'
          .input.align-right
            = f.submit "Update Stage", :class => 'button'
      .box-title Edit Permissions
      .box
        - for role in @roles
          .role{:id => "stage_role_#{role.id}"}
            = check_box_tag "stage_role_#{role.id}_check", 'checked', @stage.roles.include?(role)
            %label{:for => "stage_role_#{role.id}_check"}= h role.name
            = observe_field "stage_role_#{role.id}_check", :url => { :controller => 'stage_assignments', :action => 'update', :stage_id => @stage.id, :role_id => role.id }, :frequency => 0.5, :complete => visual_effect(:highlight, "stage_role_#{role.id}"), :method => :post
        - if @roles.length == 0
          No roles found
      - if @report_type.stages.length > 1
        .box-title Paths
        .box
          - for path in @stage.to_paths
            .path
              = link_to_remote "#{h(path.name)} &gt; #{h(path.to_stage.name)}", :url => edit_report_type_stage_path_path(@report_type, @stage, path), :update => :path, :method => :get
          .align-right
            %br
            = link_to_remote 'New Path', :url => new_report_type_stage_path_path(@report_type, @stage), :update => :path, :method => :get
    %td{:valign => 'top'}
      %img#loading_path{:src => '/images/loading.gif', :style => 'display: none;'}
      #path
